--[[
local pb = require "pb"

Buffer = {
	pos = 1,
	data = data,
	limit = 1,
}

function Buffer:Init(data)
	self.pos = 1
	self.data = data
	self.limit = #data
end

function Buffer:ReadTag()
	if self.pos >= self.limit then
		return 0
	end

	local tag, new_pos = pb.read_tag(self.data, self.pos)
	self.pos = new_pos
	return tag
end

function Buffer:ReadInt()
	local val, new_pos = pb.signed_varint_decoder(self.data, self.pos)
	self.pos = new_pos
	return val
end

function Buffer:ReadString()
	local val, new_pos = pb.signed_varint_decoder(self.data, self.pos)
	new_pos = new_pos + val
	local pos = self.pos
	self.pos = new_pos
	return string.sub(self.buffer, pos+1, new_pos)
end

function Buffer:ReadMsg(msgObj)
	local val, new_pos = pb.signed_varint_decoder(self.data, self.pos)
	new_pos = new_pos+val
	local pos = self.pos
	--self.pos = new_pos

	local oldLimit = self.limit
	self.limit = new_pos
	msgObj.Parse(self)
	self.limit = oldLimit

	return msgObj
end





Person = {
	
}

function Person:Parse(buffer, endPos)
	while True do
		local tag = buffer:ReadTag()
		if tag == 0:
			return 
		elif tag == 1:
			self.id = buffer:ReadInt()
		elif tag == 2:
			self.name = buffer:ReadString()
		elif tag == 3:
			self.email = buffer:ReadString()
		elif tag == 4:
			local msgObj = {}
			setmetatable(msgObj, Phone)
			self.phone = buffer:ReadMsg(msgObj)
		elif tag == 5:
			if self.phone1 == nil then
				self.phone1 = {}
			end
			local msgObj = {}
			setmetatable(msgObj, Phone)
			table.insert(self.phone1, buffer:ReadMsg(msgObj))
		end
	end
end

function Person:Serialize()
	if self.phone1 ~= nil then
		for k, v in ipairs(self.phone1) do
			buf:WriteMsg(5, v)
		end

	end

end



Phone = {
	
}

function Phone:Parse(buffer)
end

function Phone:Serialize()
end


]]